﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    ViewBag.Title = "题库管理";
}
<style>
    #tab1 th, #tab1 td {
        text-align: center;
    }

        #tab1 td.left {
            text-align: left;
        }

        #tab1 td.right {
            text-align: right;
        }
</style>

<div>
    <a title="考试管理" href="@Url.Action("Manager")" class="layui-btn"><i class="layui-icon layui-icon-prev"></i>考试管理</a>
</div>
<div>
</div>
<div class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">ID</label>
        <div class="layui-input-inline">
            <input id="txtID" type="number" placeholder="按ID精准查询" class="layui-input">
        </div>
        <label class="layui-form-label">题目</label>
        <div class="layui-input-inline">
            <input id="txtName" type="text" placeholder="仅按题目搜索" class="layui-input">
        </div>
        <label class="layui-form-label">题目全文</label>
        <div class="layui-input-inline">
            <input id="txtAll" type="text" placeholder="（含题目、选项、解析等）" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <button title="查询" class="layui-btn" onclick="search();"><i class="layui-icon layui-icon-search"></i>查询</button>
            <button title="清空" class="layui-btn layui-btn-primary" onclick="cleartxt();"><i class="layui-icon layui-icon-refresh"></i>清空</button>
        </div>
    </div>
</div>
<table id="tab1" class="layui-table">
    <thead>
        <tr>
            <th colspan="2">题目列表</th>
            <th class="right" width="20%">
                <a href="@Url.Action("QuestComp")" class="layui-btn"><i class="layui-icon layui-icon-add-circle"></i>添加题目</a>
            </th>
        </tr>
        <tr>
            <th width="10%">ID</th>
            <th>题目</th>
            <th width="20%">操作</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>
@section script{
    <script>
        function search() {
            let id = $("#txtID").val();
            let name = $("#txtName").val();
            let all = $("#txtAll").val();
            let lastid = $("#tab1 tr[qid]").last().attr("qid");
            lastid = isNaN(lastid) ? 0 : parseInt(lastid);
            let obj = new Object();
            obj.id = id;
            obj.name = name;
            obj.all = all;
            obj.lastid = lastid;
            layer.msg("正在保存，请稍候...", {
                icon: 16,
                time: 0,
                shade: 0.3,
                shadeClose: false
            });
            $.ajax({
                type: "POST",
                url: "@Url.Action("QuestLib_trs")",
                data: obj,
                success: function (html) {
                    layer.msg("查询完成");
                    $("#tab1 tbody").html(html);
                },
                error: function (msg) {
                    layer.msg(msg);
                }
            });
        }

        function cleartxt() {
            $("#txtID").val("");
            $("#txtName").val("");
            $("#txtAll").val("");
        }
    </script>
}